﻿Imports Microsoft.Windows.Design.Interaction
Imports Microsoft.Windows.Design.Model
Imports Microsoft.Windows.Design.Policies

<UsesItemPolicy(GetType(WPFSearchDataGridPolicy))> _
Class WPFSearchDataGridContextMenuProvider
    Inherits PrimarySelectionContextMenuProvider
    Private m_showheader As MenuAction
    Private m_showadvanced As MenuAction
    Private m_showrefresh As MenuAction
    Public Sub New()
        Dim _group As New MenuGroup("Advanced", "Advanced")
        m_showheader = New MenuAction("ShowHeader")
        m_showheader.Checkable = True
        AddHandler m_showheader.Execute, AddressOf m_showheader_Execute
        m_showadvanced = New MenuAction("ShowAdvanced")
        m_showadvanced.Checkable = True
        AddHandler m_showadvanced.Execute, AddressOf m_showadvanced_Execute
        m_showrefresh = New MenuAction("ShowRefresh")
        m_showrefresh.Checkable = True
        AddHandler m_showrefresh.Execute, AddressOf m_showrefresh_Execute
        _group.HasDropDown = True
        Items.Add(_group)
        _group.Items.Add(m_showheader)
        _group.Items.Add(m_showadvanced)
        _group.Items.Add(m_showrefresh)
        AddHandler UpdateItemStatus, AddressOf WWSearchDataGridContextMenu_UpdateItemStatus
    End Sub
    Private Sub WWSearchDataGridContextMenu_UpdateItemStatus(sender As Object, e As MenuActionEventArgs)
        Dim _parent As ModelItem = e.Selection.PrimarySelection
        Dim value As Visibility = _parent.Properties("ShowHeader").ComputedValue
        If value = Visibility.Visible Then
            m_showheader.Checked = True
        Else
            m_showheader.Checked = False
        End If
        value = _parent.Properties("ShowRefresh").ComputedValue
        If value = Visibility.Visible Then
            m_showrefresh.Checked = True
        Else
            m_showrefresh.Checked = False
        End If
        value = _parent.Properties("ShowAdvanced").ComputedValue
        If value = Visibility.Visible Then
            m_showadvanced.Checked = True
        Else
            m_showadvanced.Checked = False
        End If
    End Sub
    Private Sub m_showheader_Execute(sender As Object, e As MenuActionEventArgs)
        Dim _parent As ModelItem = e.Selection.PrimarySelection
        _parent.Properties("ShowHeader").SetValue(If(m_showheader.Checked, Visibility.Visible, Visibility.Hidden))
    End Sub
    Private Sub m_showadvanced_Execute(sender As Object, e As MenuActionEventArgs)
        Dim _parent As ModelItem = e.Selection.PrimarySelection
        _parent.Properties("ShowAdvanced").SetValue(If(m_showadvanced.Checked, Visibility.Visible, Visibility.Hidden))
    End Sub
    Private Sub m_showrefresh_Execute(sender As Object, e As MenuActionEventArgs)
        Dim _parent As ModelItem = e.Selection.PrimarySelection
        _parent.Properties("ShowRefresh").SetValue(If(m_showrefresh.Checked, Visibility.Visible, Visibility.Hidden))
    End Sub
End Class
